﻿using AutoMapper;
using HomeWork911.Api.Write.Appliaction.Commond;
using HomeWork911.Domain;
using HomeWork911.ErrorCode;
using HomeWork911.infrastrunceture;
using MediatR;

namespace HomeWork911.Api.Write.Appliaction.CommondHandler
{
    public class AddPermisionCommondHandler : IRequestHandler<AddPermisionCommond, ApiResult<int>>
    {
        private readonly IBaseIRepository<Permission> permission;
        private readonly IMapper mapper;

        public AddPermisionCommondHandler(IBaseIRepository<Permission> permission, IMapper mapper)
        {
            this.permission = permission;
            this.mapper = mapper;
        }

        public async Task<ApiResult<int>> Handle(AddPermisionCommond request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            result.Code=ApiEnum.增加成功;
            result.Msg=ApiEnum.增加成功.ToString();
            Permission permissions = mapper.Map<Permission>(request);
            await permission.Add(permissions);
            return await Task.FromResult(result);   
        }
    }
}
